package utils

import (
	"net/http"

	"github.com/astaxie/beego"
	"golang.org/x/net/proxy"
)

func GetBySS(url string) (*http.Response, error) {

	var resp *http.Response

	dialSocksProxy, err := proxy.SOCKS5("tcp", "127.0.0.1:10086", nil, proxy.Direct)
	if err != nil {

		beego.Debug("Error connecting to proxy:", err)
		SendToMail("GetBySS1", err.Error())
		return resp, err
	}
	//fmt.Println(dialSocksProxy, err)

	tr := &http.Transport{Dial: dialSocksProxy.Dial}
	// Create client
	myClient := &http.Client{
		Transport: tr,
	}
	resp, err = myClient.Get(url)
	if err != nil {

		beego.Debug("GetBySS2,input, err1 := ioutil.ReadAll(resp.Body)", err.Error())
		SendToMail("GetBySS2,input, err1 := ioutil.ReadAll(resp.Body)", err.Error())
		return nil, err

	}
	return resp, err

}
